import request from '@/utils/request'
import qs from 'qs'

export function findListByPage(params) {
  return request({
    url: '/api/data/table/list' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function findLatestSuccess(params) {
  return request({
    url: '/api/data/table/list/latestSuccess' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: '/api/data/table/list',
    method: 'post',
    data
  })
}

export function edit(data) {
  return request({
    url: '/api/data/table/list',
    method: 'put',
    data
  })
}

export function del(pkIds) {
  return request({
    url: '/api/data/table/list/' + pkIds,
    method: 'delete'
  })
}

export function buildSql(pkId) {
  return request({
    url: '/api/data/table/list/buildSql/' + pkId,
    method: 'put',
    pkId
  })
}

export function getFieldMap(sourceConnId, targetConnId, pkId) {
  return request({
    url: '/api/data/table/list/getFieldMap/' + sourceConnId + '/' + targetConnId + '/' + pkId,
    method: 'put',
    sourceConnId, targetConnId, pkId
  })
}

export function getInfoWithField(pkId) {
  return request({
    url: '/api/data/table/list/getInfoWithField/' + pkId,
    method: 'get',
    pkId
  })
}

export function downloadTemplate() {
  return request({
    url: '/api/data/table/list/template',
    method: 'get'
  })
}

export function download(params) {
  return request({
    url: '/api/data/table/list/exportTableTransfer?pkIds=' + params.join(','),
    method: 'get',
    responseType: 'blob'
  })
}

export function findAllRecords(params) {
  return request({
    url: '/api/cross/db/contrast/list/all' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export default {
  findListByPage,
  findLatestSuccess,
  add,
  edit,
  del,
  buildSql,
  getFieldMap,
  downloadTemplate,
  download,
  getInfoWithField,
  findAllRecords
}
